﻿/*
 
Celerity: Sensory Overload
Copright 2012 by Adam Hill, David Gannon, Thomas Tamblyn & Patrick Ytting
Contact: adam.hill@outlook.com
Website: adamhill.org
Licence: MS-Pl Licence
  
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Celerity.Data;

namespace Celerity.UI.Definition
{
    public class UIDrawCondition
    {
        // Game states
        public bool CheckGameState;
        public bool CheckMenuState;
        public bool CheckPauseState;
        public bool CheckMuteState;
        public bool CheckCameraState;
        public bool ExcludeMode; // Default is "must match", or set this to flip logic to "must not match"

        // Inputs
        public bool CheckWebcam;
        public bool CheckGamepad;
        public bool CheckGyro;
        public bool CheckKeyboard;

        // Counter checks
        public bool CheckLives;
        public bool CheckBombs;
        public int MinLives;
        public int MinBombs;

        // Lists of things to check
        public List<GameState> CheckedGameStates;
        public List<MenuState> CheckedMenuStates;
        public List<MuteState> CheckedMuteStates;
        public List<CameraState> CheckedCameraStates;

        public bool IsValid
        {
            get
            {
                // States
                bool gameStates = true;
                bool menuStates = true;
                bool pauseStates = true;
                bool muteStates = true;
                bool cameraStates = true;

                // Inputs
                bool initialValue = ExcludeMode ? true : false;
                bool setToValue = ExcludeMode ? false : true;
                bool webcam = true;
                bool gamepad = true;
                bool gyro = true;
                bool keyboard = true;

                // Counters
                bool livesOk = true;
                bool bombsOk = true;

                // Game state
                if (CheckGameState)
                {
                    gameStates = initialValue;
                    for (int i = 0; i < CheckedGameStates.Count(); i++)
                    {
                        if (CheckedGameStates[i] == GlobalGameStates.GameState)
                        {
                            gameStates = setToValue;
                        }
                    }
                }

                // Menu state
                if (CheckMenuState)
                {
                    menuStates = initialValue;
                    for (int i = 0; i < CheckedMenuStates.Count(); i++)
                    {
                        if (CheckedMenuStates[i] == GlobalGameStates.MenuState)
                        {
                            menuStates = setToValue;
                        }
                    }
                }

                // Mute state
                if (CheckMuteState)
                {
                    muteStates = initialValue;
                    for (int i = 0; i < CheckedMuteStates.Count(); i++)
                    {
                        if (CheckedMuteStates[i] == GlobalGameStates.MuteState)
                        {
                            muteStates = setToValue;
                        }
                    }
                }

                // Camera state
                if (CheckCameraState)
                {
                    cameraStates = initialValue;
                    for (int i = 0; i < CheckedCameraStates.Count(); i++)
                    {
                        if (CheckedCameraStates[i] == GlobalGameStates.CameraState)
                        {
                            cameraStates = setToValue;
                        }
                    }
                }

                // Inputs
                if (CheckWebcam)
                {
                    webcam = ExcludeMode ? !GlobalGameStates.ControlAvailableWebcam : GlobalGameStates.ControlAvailableWebcam;
                }
                if (CheckGamepad)
                {
                    gamepad = ExcludeMode ? !GlobalGameStates.ControlAvailableGamepad : GlobalGameStates.ControlAvailableGamepad;
                }
                if (CheckGyro)
                {
                    gyro = ExcludeMode ? !GlobalGameStates.ControlAvailableInclinometer : GlobalGameStates.ControlAvailableInclinometer;
                }
                if (CheckKeyboard)
                {
                    keyboard = ExcludeMode ? !GlobalGameStates.ControlAvailableKeyboard : GlobalGameStates.ControlAvailableKeyboard;
                }

                // Counters
                if (CheckLives)
                {
                    livesOk = GlobalGameStates.LivesLeft >= MinLives;
                }
                if (CheckBombs)
                {
                    bombsOk = GlobalGameStates.BombsLeft >= MinBombs;
                }

                // Overall valid state
                return gameStates && menuStates && pauseStates && muteStates && cameraStates && webcam && gamepad && gyro && keyboard && livesOk && bombsOk;
            }
        }
    }
}
